<template>
  <div>
    <operation-title
      title="商品排行"
      :icon="TitleIcon"
    />
    <div class="divider" />
    <div class="func">
      <p class="attr">
        选择风格
      </p>
      <ul class="common-ul">
        <li
          :class="config.pageConfig.custom == '3' ? 'active' : ''"
          @click="changeCustom('3')"
        >
          <img
            src="../../../../../../assets/app/other/goods/goods-three.png"
            alt=""
          >
        </li>
        <li
          :class="config.pageConfig.custom == '2' ? 'active' : ''"
          @click="changeCustom('2')"
        >
          <img
            src="/src/assets/app/other/goods/goods-two.png"
            alt=""
          >
        </li>
        <li
          :class="config.pageConfig.custom == '7' ? 'active' : ''"
          @click="changeCustom('7')"
        >
          <img
            src="../../../../../../assets/app/other/goods/goods-seven.png"
            alt=""
          >
        </li>
      </ul>
    </div>
    <div class="divider" />
    <div class="func">
      <p class="attr">
        样式
      </p>
      <ul class="common-ul">
        <li
          :class="config.pageConfig.style == '1' ? 'active' : ''"
          @click="config.pageConfig.style = '1'"
        >
          默认
        </li>
        <li
          :class="config.pageConfig.style == '2' ? 'active' : ''"
          @click="config.pageConfig.style = '2'"
        >
          投影
        </li>
        <li
          :class="config.pageConfig.style == '3' ? 'active' : ''"
          @click="config.pageConfig.style = '3'"
        >
          描边
        </li>
      </ul>
      <div
        v-if="config.pageConfig.style == '3'"
        class="adjust-item"
      >
        <el-color-picker v-model="config.pageConfig.borderColor" />
        <span>{{ config.pageConfig.borderColor }}</span>
      </div>
      <div
        v-if="config.pageConfig.style == '3'"
        class="adjust-item"
      >
        <el-slider
          v-model="config.pageConfig.borderWidth"
          :min="0"
          :max="5"
          show-input
          size="small"
        />px
      </div>
    </div>
    <div class="divider" />
    <div class="tips-rank">
      展示店铺前三个热销商品排行，可展示整店热销商品，也可以是某个类目的热销商品，快速引导消费者购买店铺爆款。
    </div>
    <div class="func">
      <p class="attr">
        标题
      </p>
      <div class="adjust-item">
        <el-radio-group v-model="config.pageConfig.titleShow">
          <el-radio :label="true">
            显示
          </el-radio>
          <el-radio :label="false">
            隐藏
          </el-radio>
        </el-radio-group>
      </div>
      <div
        v-if="config.pageConfig.titleShow"
        class="add-item"
      >
        <div class="add-item-input">
          <p>文字</p>
          <el-input
            v-model="config.pageConfig.title"
            maxlength="8"
            :show-word-limit="true"
          />
        </div>
        <div class="add-item-input">
          <p>颜色</p>
          <el-color-picker v-model="config.pageConfig.titleColor" />
          <span>{{ config.pageConfig.titleColor }}</span>
        </div>
        <div class="add-item-input">
          <p>线条</p>
          <el-color-picker v-model="config.pageConfig.titleLineColor" />
          <span>{{ config.pageConfig.titleLineColor }}</span>
        </div>
        <div class="add-item-input">
          <p>图片</p>
          <div class="img-placeholder">
            <div
              v-if="config.pageConfig.titleImg"
              class="upload-img"
            >
              <el-image
                style="width: 100%; height: 100%"
                :src="config.pageConfig.titleImg"
                fit="contain"
              />
              <div class="upload-img_cover">
                <Upload
                  :model-value="titlefileList"
                  file-path="actapp/"
                  :limit="999"
                  :show-file-list="false"
                  @success="success"
                >
                  <el-button size="small">
                    替换
                  </el-button>
                </Upload>
              </div>
            </div>
            <Upload
              v-else
              v-model="config.pageConfig.titleImg"
              file-path="actapp/"
              list-type="picture-card"
            >
              <el-icon>
                <Plus />
              </el-icon>
            </Upload>
          </div>
        </div>
      </div>
    </div>
    <div class="divider" />
    <!--        选择商品-->
    <select-goods-setting
      :page-config="config.pageConfig"
      :disable-types="['manual']"
    />
    <div class="divider" />
    <div class="func">
      <p class="attr">
        显示条数
      </p>
      <div class="adjust-item">
        <el-slider
          v-model="config.pageConfig.showCount"
          :min="1"
          :max="20"
          show-input
          size="small"
        />
        {{ config.pageConfig.showCount }}条
      </div>
    </div>
    <div class="divider" />
    <!-- <div class="func">
            <p class="attr">关键字</p>
            <div class="adjust-item">
                <el-input v-model="config.pageConfig.keyword" maxlength="20" :show-word-limit="true" />
            </div>
        </div>
        <div class="divider"></div>
        <div class="func">
            <p class="attr">过滤价格</p>
            <div class="adjust-item">
                <el-input v-model="config.pageConfig.lowPrice" class="price-range">
                    <template #append>元</template>
                </el-input>
                &nbsp;--&nbsp;
                <el-input v-model="config.pageConfig.highPrice" class="price-range">
                    <template #append>元</template>
                </el-input>
            </div>
        </div>
        <div class="divider"></div>-->
    <div class="func">
      <p class="attr">
        颜色设置
      </p>
      <div class="adjust-item">
        <span>底部背景</span>
        <el-color-picker v-model="config.pageConfig.color" />
        <span>{{ config.pageConfig.color }}</span>
      </div>
      <div class="adjust-item">
        <span>商品背景</span>
        <el-color-picker v-model="config.pageConfig.goodsColor" />
        <span>{{ config.pageConfig.goodsColor }}</span>
      </div>
    </div>
    <div class="divider" />

    <!--    显示内容-->
    <goods-content-setting v-model:page-config="config.pageConfig" />

    <div class="divider" />

    <!--    内容对齐-->
    <content-alignment
      v-if="config.pageConfig.custom === '7'"
      v-model:page-config="config.pageConfig"
    />

    <div class="divider" />

    <!--    购买按钮-->
    <purchase-button-setting :page-config="pageConfig" />

    <div class="divider" />

    <div class="func">
      <p class="attr">
        边距
      </p>
      <div class="adjust-item">
        <span>商品间距</span>
        <el-slider
          v-model="config.pageConfig.distance"
          :min="0"
          :max="20"
          show-input
          size="small"
        />px
      </div>
      <div class="adjust-item">
        <span>上边距</span>
        <el-slider
          v-model="config.pageConfig.marginTop"
          :min="0"
          :max="50"
          show-input
          size="small"
        />px
      </div>
      <div class="adjust-item">
        <span>下边距</span>
        <el-slider
          v-model="config.pageConfig.marginBottom"
          :min="0"
          :max="50"
          show-input
          size="small"
        />px
      </div>
      <div class="adjust-item">
        <span>左右边距</span>
        <el-slider
          v-model="config.pageConfig.margin"
          :min="0"
          :max="20"
          show-input
          size="small"
        />px
      </div>
    </div>
    <div class="divider" />
    <div class="func">
      <p class="attr">
        圆角设置
      </p>
      <div class="adjust-item">
        <span>上圆角</span>
        <el-slider
          v-model="config.pageConfig.radiusTop"
          :min="0"
          :max="20"
          show-input
          size="small"
        />px
      </div>
      <div class="adjust-item">
        <span>下圆角</span>
        <el-slider
          v-model="config.pageConfig.radiusBottom"
          :min="0"
          :max="20"
          show-input
          size="small"
        />px
      </div>
    </div>
    <div class="divider" />
  </div>
</template>

<script lang="ts">
export default {
  name: "RankOperation",
};
</script>
<script lang="ts" setup>
import { onMounted } from "vue";
import { getAllCategory } from "@/api/actapp";
import { useMallConfig } from "@/views/pointsMall/compositions/useMallConfig";
import PurchaseButtonSetting
  from "@/views/activity/actApp/components/default/operationComponents/purchaseButtonSetting/PurchaseButtonSetting.vue";
import {
  IPurchaseButtonPageConfig,
  purchaseButtonPageConfig
} from "../operationComponents/purchaseButtonSetting";
import SelectGoodsSetting
  from "@/views/activity/actApp/components/default/operationComponents/selectGoodsSetting/SelectGoodsSetting.vue";
import {
  ISelectGoodsSettingPageConfig,
  selectGoodsSettingPageConfig
} from "../operationComponents/selectGoodsSetting";
import GoodsContentSetting
  from "@/views/activity/actApp/components/default/operationComponents/goodsContentSetting/GoodsContentSetting.vue";
import {
  goodsContentSettingPageConfig,
  IGoodsContentSettingPageConfig
} from "../operationComponents/goodsContentSetting";
import ContentAlignment
  from "@/views/activity/actApp/components/default/operationComponents/contentAlignment/ContentAlignment.vue";
import {
  contentAlignmentPageConfig,
  IContentAlignmentPageConfig
} from "../operationComponents/contentAlignment";
import TitleIcon from "@/assets/app/icon/goodsRanking.png";
import OperationTitle
  from "@/views/activity/actApp/components/default/operationComponents/operationTitle/OperationTitle.vue";


interface IPageConfig extends
    IPurchaseButtonPageConfig,
    ISelectGoodsSettingPageConfig,
    IGoodsContentSettingPageConfig,
    IContentAlignmentPageConfig
{
  custom: string;
  style: string;
  borderWidth: number;
  borderColor: string;
  titleLineColor: string;
  title: string;
  titleImg: string;
  titleShow: boolean;
  classifyId: string;
  showCount: number;
  keyword: string;
  lowPrice: string;
  highPrice: string;
  color: string;
  goodsColor: string;
  goodsTitleShow: boolean;
  goodsTitlecolor: string;
  distance: number;
  marginTop: number;
  marginBottom: number;
  margin: number;
  radiusTop: number;
  radiusBottom: number;
  mallId: number | undefined;
}

const config = withDefaults(defineProps<{
  pageConfig: IPageConfig,
}>(), {
  pageConfig: () => ({
    custom: "1",
    style: "1",
    borderWidth: 1,
    borderColor: "#ededed",
    titleLineColor: "#333",
    title: '商品排行',
    titleImg: './imagesStatic/1662518195000G6B5ranking.png',
    titleShow: true,
    classifyId: "",
    showCount: 1,
    keyword: '',
    lowPrice: '',
    highPrice: '',
    color: "",
    goodsColor: "#fff",
    goodsTitlecolor: "#999ca7",
    distance: 10,
    marginTop: 10,
    marginBottom: 10,
    margin: 10,
    radiusTop: 4,
    radiusBottom: 4,
    mallId: undefined,
    ...purchaseButtonPageConfig,
    ...selectGoodsSettingPageConfig,
    goodsChooseType: "category",
    ...goodsContentSettingPageConfig,
    ...contentAlignmentPageConfig,
  })
});

const { mallConfig } = useMallConfig()

const titlefileList = ref([]);

const emits = defineEmits<{ (e: "changeStyle", configStyle: Object): void }>();
const uploadSuccess = (value: any) => {
  config.pageConfig.carUrl = value.url;
};

const success = (value: any) => {
  config.pageConfig.titleImg = value.url;
};

const changeCustom = (custom: string) => {
  config.pageConfig.custom = custom;

  if (custom !== '7') {
    config.pageConfig.contentAlignment = "left";
  }
}

watch(config, (val) => {
  emits("changeStyle", config.pageConfig);
});

onMounted(() => {
  config.pageConfig.mallId = mallConfig.value.id;
  // getClassifyList()
})
</script>

<style lang="scss" scoped>
.title {
  padding: 8px 23px;
  overflow: hidden;
  border-bottom: 5px solid #f6f7f9;
  display: flex;
  position: relative;
  height: 50px;
  box-sizing: border-box;

  img {
    position: absolute;
    left: 0;
    top: -5px;
  }

  h5 {
    font-size: 16px;
    font-weight: 700;
    position: absolute;
    left: 70px;
    top: 0;
    line-height: 50px;
  }
}

.func {
  border-bottom: 5px solid #f6f7f9;
  padding: 20px 16px;
  font-size: 16px;

  .attr {
    line-height: 1;
    color: #47565d;
    font-weight: bolder;
    margin-bottom: 20px;

    span {
      font-size: 14px;
      font-weight: 400;
      color: red;
    }
  }

  ul.common-ul {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: center;

    li {
      flex: 1;
      height: 30px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 4px 0 0 4px;
      border: 2px solid #ededed;
      border-collapse: collapse;

      &.active {
        border: 2px solid #fb6638;
      }

      img {
        max-width: 100% !important;
        max-height: 100% !important;
      }
    }
  }

  h4 {
    position: relative;
    padding: 8px 16px 8px 16px;
    border-radius: 6px;
    color: red;
    font-size: 16px;
    line-height: 22px;
    margin-bottom: 10px;
    border: 1px solid #d8e8fc;
    background-color: #e5f0fe;
  }

  div.adjust-item {
    display: flex;
    align-items: center;
    margin-top: 10px;
    margin-bottom: 10px;

    span {
      width: 64px;
      text-align: right;
      margin-right: 15px;
      color: #666;
    }

    :deep(.el-slider) {
      width: 240px;
      margin-right: 3px;
      margin-left: 15px;
    }

    :deep(.el-checkbox) {
      width: 100px;
      margin-right: 13px;
    }

    :deep(.el-color-picker) {
      margin-right: 13px;
    }

    :deep(.el-slider__runway.show-input) {
      margin-right: 15px;
    }

    :deep(.el-input-number) {
      width: 100px;
      background: #f4f3f7;
      border: 1px solid #f4f3f7;
    }

    .input-content {
      width: 200px;
    }

    .price-range {
      width: 150px;
    }

    .common-ul {
      width: 200px;
    }
  }

  .add-item {
    width: 100%;

    .add-item-input {
      background: #f4f3f7;
      border-radius: 4px;
      padding: 10px 20px 0px 10px;
      color: #999;
      //   margin-top: 10px;
      //   margin-bottom: 20px;
      position: relative;
      display: flex;

      p {
        width: 60px;
      }

      :deep(.el-input) {
        font-size: 12px;
        height: 30px;
        width: calc(100% - 60px);
      }

      &.extra-li {
        justify-content: center;
      }

      .link-div {
        width: calc(100% - 80px);
        display: flex;
        align-items: center;
        background: #e8effc;
        border: 0;
        padding-left: 16px;
        cursor: pointer;
        position: relative;

        :deep(.el-icon) {
          margin-right: 10px;
        }

        :deep(.el-input) {
          font-size: 12px;
          height: 30px;
          width: calc(100% - 30px);
        }

        .close-btn {
          position: absolute;
          right: 5px;
        }
      }

      .sure-close {
        position: absolute;
        right: 5px;
        top: 5px;
        cursor: pointer;
      }
    }
  }
}

.tips-rank {
  position: relative;
  padding: 8px 16px 8px 16px;
  border-radius: 6px;
  color: #666;
  font-size: 12px;
  line-height: 22px;
  margin-bottom: 10px;
  border: 1px solid #d8e8fc;
  background-color: #e5f0fe;
}

:deep(.el-radio__label) {
  font-size: 16px;
}

.img-placeholder {
  width: 80px;
  height: 80px;
  margin-bottom: 10px;
}

.upload-img {
  width: 80px;
  height: 80px;
  line-height: 80px;
  margin-right: 10px;
  border: 1px dashed #ededed;
  text-align: center;
  color: #dad9d9;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  float: left;
  position: relative;

  :deep(.el-image) {
    width: 80px;
    height: 80px;
  }

  &:hover {
    .upload-img_cover {
      opacity: 1;
    }
  }

  .upload-img_cover {
    opacity: 0;
    position: absolute;
    transition: all 0.3s ease;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
  }
}

:deep(.el-upload-list) {
  width: 80px;
  height: 80px;
  margin-right: 10px;
}

:deep(.el-upload--picture-card) {
  width: 80px;
  height: 80px;
}
</style>
